package org.dromara.miniapp.common;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.service.DictService;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 字典 控制层 Eloquence evaluation
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/dict")
public class ApiDictController extends BaseController {
    
    private final DictService dictService;
    
    /**
     * 字典查询
     *
     * @param dictType 字典类型,具体的字典类型问后端
     */
    @SaIgnore
    @Log(title = "字典查询", businessType = BusinessType.OTHER)
    @PostMapping(value = "/{dictType}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Map<String, String>> getAllDictByDictType(@PathVariable String dictType) {
        if (ObjectUtil.isNull(dictType)) {
            return R.fail("字典类型不能为空");
        }
        Map<String, String> allDictByDictType = dictService.getAllDictByDictType(dictType);
        return R.ok(allDictByDictType);
    }
    
}
